Skip to content

fix(providers): fail loudly on malformed chat completion responses (#267) - #276

Merged
David-patrick-chuks-02 merged 2 commits into
Lilly-Protocol:mainfrom
ghzhost:fix/openai-provider-malformed-response-267
Sep 6, 2026
Merged

fix(providers): fail loudly on malformed chat completion responses (#267)#276
David-patrick-chuks-02 merged 2 commits into
Lilly-Protocol:mainfrom
ghzhost:fix/openai-provider-malformed-response-267

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Addresses #267 by validating the chat completion response structure in OpenAICompatibleModelProvider.generate():

  1. JSON parsing guard: Parses response body text safely and catches parse errors, throwing a descriptive error with HTTP status and body excerpt.
  2. Response structure validation: Validates that the payload is an object and contains a non-empty choices array.
  3. Choice message validation: Validates that choices[0] is an object containing string message.content.
  4. Unit test coverage: Adds unit tests verifying rejections on non-JSON response body with HTTP status/excerpt context, empty choices array, missing choices, and missing/non-string message content. All existing tests continue to pass.

Closes #267

@David-patrick-chuks-02
David-patrick-chuks-02 merged commit 4e50081 into Lilly-Protocol:main Sep 6, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty: $90] Fail loudly on malformed chat completion responses in OpenAICompatibleModelProvider

3 participants